<!DOCTYPE html>

<html>
<head>
  <title>escape.js</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="..\..\..\docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
    <ul class="sections">
        
          <li id="title">
              <div class="annotation">
                  <h1>escape.js</h1>
              </div>
          </li>
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <p>Escape nodes are used for escape sequences. It is rendered as a label with
the description of the escape and the numeric code it matches when
appropriate.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
<span class="hljs-keyword">import</span> _ <span class="hljs-keyword">from</span> <span class="hljs-string">'lodash'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">hex</span>(<span class="hljs-params">value</span>) </span>{
  <span class="hljs-keyword">var</span> str = value.toString(<span class="hljs-number">16</span>).toUpperCase();

  <span class="hljs-keyword">if</span> (str.length &lt; <span class="hljs-number">2</span>) {
    str = <span class="hljs-string">'0'</span> + str;
  }

  <span class="hljs-keyword">return</span> <span class="hljs-string">`(0x<span class="hljs-subst">${str}</span>)`</span>;
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  <span class="hljs-attr">type</span>: <span class="hljs-string">'escape'</span>,</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <p>Renders the escape into the currently set container.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  _render() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.renderLabel(<span class="hljs-keyword">this</span>.label)
      .then(<span class="hljs-function"><span class="hljs-params">label</span> =&gt;</span> {
        label.select(<span class="hljs-string">'rect'</span>).attr({
          <span class="hljs-attr">rx</span>: <span class="hljs-number">3</span>,
          <span class="hljs-attr">ry</span>: <span class="hljs-number">3</span>
        });
        <span class="hljs-keyword">return</span> label;
      });
  },

  setup() {
    <span class="hljs-keyword">let</span> addHex;</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <p>The escape code. For an escape such as <code>\b</code> it would be “b”.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="hljs-keyword">this</span>.code = <span class="hljs-keyword">this</span>.properties.esc.properties.code.textValue;</pre></div></div>
            
        </li>
        
        
        <li id="section-4">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-4">&#182;</a>
              </div>
              <p>The argument. For an escape such as <code>\xab</code> it would be “ab”.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="hljs-keyword">this</span>.arg = <span class="hljs-keyword">this</span>.properties.esc.properties.arg.textValue;</pre></div></div>
            
        </li>
        
        
        <li id="section-5">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-5">&#182;</a>
              </div>
              <p>Retrieves the label, ordinal value, an flag to control adding hex value
from the escape code mappings</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    [<span class="hljs-keyword">this</span>.label, <span class="hljs-keyword">this</span>.ordinal, addHex] = _.result(<span class="hljs-keyword">this</span>, <span class="hljs-keyword">this</span>.code);
  },</pre></div></div>
            
        </li>
        
        
        <li id="section-6">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-6">&#182;</a>
              </div>
              <p>Escape code mappings</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  b: [<span class="hljs-string">'单词边界'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-attr">B</span>: [<span class="hljs-string">'非单词边界'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-attr">d</span>: [<span class="hljs-string">'数字'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-attr">D</span>: [<span class="hljs-string">'非数字'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-attr">f</span>: [<span class="hljs-string">'换页符'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">true</span>],
  <span class="hljs-attr">n</span>: [<span class="hljs-string">'换行符'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">true</span>],
  <span class="hljs-attr">r</span>: [<span class="hljs-string">'回车符'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">true</span>],
  <span class="hljs-attr">s</span>: [<span class="hljs-string">'空白字符'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-attr">S</span>: [<span class="hljs-string">'非空白字符'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-attr">t</span>: [<span class="hljs-string">'水平制表符'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">true</span>],
  <span class="hljs-attr">v</span>: [<span class="hljs-string">'垂直制表符'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">true</span>],
  <span class="hljs-attr">w</span>: [<span class="hljs-string">'单词'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-attr">W</span>: [<span class="hljs-string">'非单词'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-number">1</span>: [<span class="hljs-string">'向后引用 (普通分组 = 1)'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-number">2</span>: [<span class="hljs-string">'向后引用 (普通分组 = 2)'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-number">3</span>: [<span class="hljs-string">'向后引用 (普通分组 = 3)'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-number">4</span>: [<span class="hljs-string">'向后引用 (普通分组 = 4)'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-number">5</span>: [<span class="hljs-string">'向后引用 (普通分组 = 5)'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-number">6</span>: [<span class="hljs-string">'向后引用 (普通分组 = 6)'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-number">7</span>: [<span class="hljs-string">'向后引用 (普通分组 = 7)'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-number">8</span>: [<span class="hljs-string">'向后引用 (普通分组 = 8)'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-number">9</span>: [<span class="hljs-string">'向后引用 (普通分组 = 9)'</span>, <span class="hljs-number">-1</span>, <span class="hljs-literal">false</span>],
  <span class="hljs-number">0</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.arg) {
      <span class="hljs-keyword">return</span> [<span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-built_in">String</span>.fromCharCode(<span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.arg, <span class="hljs-number">8</span>))}</span>(octal: 0<span class="hljs-subst">${<span class="hljs-keyword">this</span>.arg.toUpperCase()}</span>)`</span>,<span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.arg, <span class="hljs-number">8</span>), <span class="hljs-literal">false</span>];
    } <span class="hljs-keyword">else</span> {
      <span class="hljs-keyword">return</span> [<span class="hljs-string">'null'</span>, <span class="hljs-number">0</span>, <span class="hljs-literal">true</span>];
    }
  },
  c() {
    <span class="hljs-keyword">return</span> [<span class="hljs-string">`Ctrl + <span class="hljs-subst">${<span class="hljs-keyword">this</span>.arg.toUpperCase()}</span>`</span>, <span class="hljs-keyword">this</span>.arg.toUpperCase().charCodeAt(<span class="hljs-number">0</span>) - <span class="hljs-number">64</span>, <span class="hljs-literal">false</span>];
  },
  x() {
    <span class="hljs-keyword">return</span> [<span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-built_in">String</span>.fromCharCode(<span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.arg, <span class="hljs-number">16</span>))}</span>(hex: 0x<span class="hljs-subst">${<span class="hljs-keyword">this</span>.arg.toUpperCase()}</span>)`</span>,<span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.arg, <span class="hljs-number">16</span>), <span class="hljs-literal">false</span>];
  },
  u() {
    <span class="hljs-keyword">var</span> unicode = <span class="hljs-built_in">unescape</span>(<span class="hljs-string">"%u"</span> + <span class="hljs-keyword">this</span>.arg.replace(<span class="hljs-regexp">/\%u/g</span>, <span class="hljs-string">"%u"</span>));
    <span class="hljs-keyword">return</span> [<span class="hljs-string">`<span class="hljs-subst">${unicode}</span>(unicode: U+<span class="hljs-subst">${<span class="hljs-keyword">this</span>.arg.toUpperCase()}</span>)`</span>, <span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.arg, <span class="hljs-number">16</span>), <span class="hljs-literal">false</span>];
  }
};</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
